package com.ruoyi.project.newhope.warningLog.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.newhope.warningLog.domain.NewHopeWarningLog;
import com.ruoyi.project.newhope.warningLog.service.INewHopeWarningLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报警记录日志Controller
 * 
 * @author ruoyi
 * @date 2021-02-08
 */
@Controller
@RequestMapping("/api/newhope/warningLog")
public class NewHopeWarningLogController extends BaseController
{

    @Autowired
    private INewHopeWarningLogService newHopeWarningLogService;

    /**
     * 查询报警记录日志列表
     */
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewHopeWarningLog newHopeWarningLog)
    {
        startPage();
        List<NewHopeWarningLog> list = newHopeWarningLogService.selectNewHopeWarningLogList(newHopeWarningLog);
        return getDataTable(list);
    }

    /**
     * 查询报警记录日志列表all
     */
    @GetMapping("/getAll")
    @ResponseBody
    public List<NewHopeWarningLog> getAll(NewHopeWarningLog newHopeWarningLog)
    {
        List<NewHopeWarningLog> list = newHopeWarningLogService.selectNewHopeWarningLogList(newHopeWarningLog);
        return list;
    }

    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestBody NewHopeWarningLog warningLog)
    {
        List<NewHopeWarningLog> list = newHopeWarningLogService.selectNewHopeWarningLogList(warningLog);
        ExcelUtil<NewHopeWarningLog> util = new ExcelUtil<>(NewHopeWarningLog.class);
        return util.exportExcel(list, "检测数据");
    }

    /**
     * 新增保存报警记录日志
     */
    @Log(title = "报警记录日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody NewHopeWarningLog newHopeWarningLog)
    {
        return toAjax(newHopeWarningLogService.insertNewHopeWarningLog(newHopeWarningLog));
    }

    /**
     * 修改报警记录日志
     */
    @GetMapping("/edit/{id}")
    @ResponseBody
    public NewHopeWarningLog edit(@PathVariable("id") Long id)
    {
        NewHopeWarningLog newHopeWarningLog = newHopeWarningLogService.selectNewHopeWarningLogById(id);
        return newHopeWarningLog;
    }

    /**
     * 修改保存报警记录日志
     */
    @Log(title = "报警记录日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody NewHopeWarningLog newHopeWarningLog)
    {
        return toAjax(newHopeWarningLogService.updateNewHopeWarningLog(newHopeWarningLog));
    }

    /**
     * 删除报警记录日志
     */
    @Log(title = "报警记录日志", businessType = BusinessType.DELETE)
    @GetMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String id)
    {
        return toAjax(newHopeWarningLogService.deleteNewHopeWarningLogByIds(id));
    }
}
